package com.headStorm.socket.mina;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.filter.codec.ProtocolCodecFilter;

/**
 * @author zhangqq
 * @create 2020-12-29 15:34
 **/
public class MinaTest {

    public static void main(String[] args) {
        TcpClient tcpClient = new TcpClient();
        MessageHandler handler = new MessageHandler();
        MessageEncoder encoder = new MessageEncoder();
        MessageDecoder decoder = new MessageDecoder();
        tcpClient.setFilter(new ProtocolCodecFilter(new SimpleCodecFactory(
                decoder, encoder)));
        tcpClient.setHandler(handler);
        tcpClient.initial();
        boolean connect = tcpClient.connect();
        byte[] yom = "helloworld".getBytes();
        tcpClient.send(IoBuffer.wrap("helloworld".getBytes()));
        if (connect) {
            System.out.println("连接成功");
        }
    }
}
